#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

#define Numbers 500

int cycles;

int prime_list(int* prime, int num) {
    int n, j, k;
    int q, r;
    int skip = 0;

    prime[0] = 2;
    n = 3;

    for (j = 1; j < num; j++) {
        prime[j] = n;

        while (n += 2) {

            for (k = 2; ; k++) {

                cycles += 1;
                q = n / prime[k - 1];
                r = n % prime[k - 1];

                if (r == 0) {
                    break;
                }

                if (q <= prime[k - 1]) {
                    skip = 1;
                    break;
                }
            }

            if (skip) {
                skip = 0;
                break;
            }
        }
    }
    return 0;
}

int printf_prime(int* prime, int num) {
    int i;
    printf("First\t\tFive\t\tHunderd\t\tPrimes");

    for (i = 0; i < num; i++) {
        if (i % 10 == 0) {
            printf("\n");
        }
        printf("%7ld", prime[i]);
    }
    printf("\n");

    return 0;
}


int main() {

    int Primes[Numbers];

    prime_list(Primes, Numbers);
    printf_prime(Primes, Numbers);
    printf("\ncycles: %d\n", cycles);
    return 0;
}